﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kugar.Core.ExtMethod;
using Kugar.Tool.MongoDBHelper;
using MongoDB.Bson;

namespace Kugar.Core.PluginFramework.PluginTest.MongoDBPlugin
{
    public class MongoStateCachePlugin:PluginBase
    {
        private MongoDBContextHelper _helper = null;

        public override int Version { get; }
        public override string PluginName => "MongoState";

        public MongoStateCachePlugin()
        {
            _helper=new MongoDBContextHelper("mongodb://42.159.241.114:37018/GPSServer", "GPSServer");

            //_helper = new MongoDBContextHelper("mongodb://localhost:27017", "");
            //_helper = new MongoDBContextHelper("42.159.241.114", "O2ODBSystem", 30317, "", "");
            //_helper = new MongoDBContextHelper("localhost", "admin", 27017, "", "");

            //查询服务器版本号和主机操作系统 {"buildInfo", 1}
            //列出服务器上所有的数据库   {"listDatabases", 1}---不过数据库必须是admin-才可查询"localhost", "admin", 27017, "", ""
            //返回这台服务器的管理统计信息 {"serverStatus", 1}
            //查看对本集合执行的最后一次操作的错误信息或者其它状态信息{"getLastError", 1}


            //返回指定集合的统计信息，包括数据大小、已分配的存储空间和索引的大小  {"collStats", ""}-无法调用
            var command = new BsonDocument
            {
                {"collStats", "base_Customer"}
            };


            var reback = _helper.RunCommand(command);
        }

        public string GetAdminFromDB()
        {
            return _helper.GetCollection("base_AdminUser").FindAll().Select(x=>x.GetObjectId("_id").ToStringEx()).JoinToString();
        }
    }
}